﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Netcare.Test
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class HostTest
    {
        public HostTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void GetProcessesTest()
        {
            using (Host sc = new Host())
            {
                //sc.Url = "http://localhost:55555";
                sc.Url = "http://218.65.250.226:55555/";

                var list = sc.GetProcesses();
                if (list == null)
                {
                    TestContext.WriteLine("Cannot get system processes");
                }
                else
                    foreach (var p in list)
                    {
                        TestContext.WriteLine("Process->ID={0}, Image={1}, Path={2}", p.ProcessId, p.ImageName, p.FullPath);
                    }
            }
        }

        [TestMethod]
        public void KillProcessTest()
        {
            using (Host sc = new Host())
            {
                sc.Url = "http://132.159.152.168:55555";

                sc.KillProcess(5831);
            }
        }

        [TestMethod]
        public void GetSystemInfoTest()
        {
            using (Host sc = new Host())
            {
                sc.Url = "http://132.159.152.168:55555/";

                var info = sc.GetSystemInfo();
                if (info == null)
                {
                    TestContext.WriteLine("Cannot get system info");
                }
                else
                {
                    TestContext.WriteLine("OperatingSystem->{0}", info.OperatingSystem);
                    TestContext.WriteLine("Product->{0}", info.Product);
                    TestContext.WriteLine("Manufactory->{0}", info.Manufactory);
                    TestContext.WriteLine("Version->{0}", info.Version);
                    TestContext.WriteLine("ComputerName->{0}", info.ComputerName);
                    TestContext.WriteLine("Architecture->{0}", info.Architecture);
                }
            }
        }


        [TestMethod]
        public void GetAgentInfoTest()
        {
            using (Host sc = new Host())
            {
                //sc.Url = "http://192.168.1.142:55555";
                //sc.Url = "http://127.0.0.1:55555";
                sc.Url = "http://132.159.152.168:55555/";

                var s = sc.GetAgentInfo();
                TestContext.WriteLine(s);
            }
        }

        [TestMethod]
        public void RestartServiceTest()
        {
            using (Host sc = new Host())
            {
                sc.Url = "http://192.168.117.133:55555";
               // sc.Url = "http://127.0.0.1:55555";
                var s = sc.RestartService("cups");
                TestContext.WriteLine(s.ToString());
            }
        }

        [TestMethod]
        public void RestartOS()
        {
            using(Host sc = new Host())
            {
                sc.Url = "http://132.159.152.167:55555";
                //sc.Url = "http://127.0.0.1:55555";
                sc.RestartOS();
                //TestContext.WriteLine(s.ToString());
            }
        }

        [TestMethod]
        public void MemoryRelease()
        {
            using (Host sc=new Host())
            {
                sc.Url = "http://192.168.117.112:55555";
                sc.MemoryRelease(1);
            }
        }

        [TestMethod]
        public void DiskDefragTest1()
        {
            using (Host sc = new Host())
            {
                sc.Url = "http://localhost:55555";
                RunType rv = RunType.Run;
                ReturnValue i = sc.DiskRelease(rv);
                TestContext.WriteLine(i.ToString());
            }
        }

        [TestMethod]
        public void DiskDefragTest2()
        {
            using (Host sc = new Host())
            {
                sc.Url = "http://localhost:55555";
                RunType rv = RunType.Check;
                ReturnValue i = sc.DiskRelease(rv);
                TestContext.WriteLine(i.ToString());
            }
        }

        [TestMethod]
        public void EnumService()
        {
            using (Host sc = new Host())
            {
                sc.Url = "http://127.0.0.1:55555";
                ServiceInfo[] info = sc.EnumServices();
                foreach (var s in info)
                {
                    TestContext.WriteLine(s.ShortName + "---" + s.Status);
                }
            }
        }

        [TestMethod]
        public void EnumService2()
        {
            using (Host sc = new Host())
            {
                sc.Url = "http://192.168.1.115:55555";
                ServiceInfo[] info = sc.EnumServices();
                foreach (var s in info)
                {
                    TestContext.WriteLine(s.ShortName + "---" + s.Status);
                }
            }
        }
    }
}
